<!DOCTYPE html>
<html lang="en">

<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>Document</title>
    <link rel="stylesheet" href="./font/iconfont.css">
    <style>
        * {
            margin: 0;
            padding: 0;
        }

        #app {
            box-sizing: border-box;
            padding: 10px;
            background-color: white;
        }

        #app .title {
            width: 50%;
            height: 50px;
            line-height: 50px;
            font-size: 24px;
            display: inline-block;
        }

        #app .delete {
            display: inline-block;
            text-align: right;
            width: 50%;
            height: 50px;
            line-height: 50px;
            font-size: 24px;
            float: right;
        }

        #app .list .item {
            display: flex;
            align-items: center;
            font-size: 18px;
            margin-bottom: 10px;
        }

        #app .list .item .left {
            width: 30%;
        }

        #app .list .item .left img {
            width: 100%;
        }

        #app .list .item .middle {
            margin-left: 4%;
        }

        #app .list .item .middle .name {
            margin-bottom: 20px;
        }

        #app .list .item .middle .smallBox .money {
            color: red;
        }

        #app .list .item .middle .smallBox .desc {
            font-size: 14px;
            color: gray;
        }

        #app .list .item .right {
            flex: 1;
            line-height: 50%;
        }

        #app .list .item .right .jianBox {
            width: 15px;
            height: 15px;
            border: 2px solid rgb(0, 110, 255);
            line-height: 13px;
            text-align: center;
            float: right;
            margin-right: 10px;
            border-radius: 15px;
        }

        #app .list .item .right .status {
            float: right;
            margin-right: 10px;
            margin-top: 5px;
        }

        #app .list .item .right .jiaBox {
            width: 19px;
            height: 19px;
            background-color: rgb(0, 110, 255);
            color: white;
            line-height: 17px;
            text-align: center;
            float: right;
            border-radius: 19px;
        }

        #app .bottom {
            line-height: 50px;
            display: flex;
            justify-content: space-around;
            text-align: center;
        }

        #app .bottom .price {
            width: 50%;
        }

        #app .bottom .count {
            flex: 1;
        }
    </style>
</head>

<body>
    <div id="app">
        <div class="title">已选商品</div>
        <div class="delete" @click="clean"><span class="iconfont icon-shanchu" style="font-size: 24px;"></span> 清空</div>
        <div class="list">
            <div class="item" v-for="(item,index) in tasklist" v-bind:key="index">
                <div class="left">
                    <img v-bind:src="item.pic" alt="">
                </div>
                <div class="middle">
                    <div class="name"> {{ item.name }}</div>
                    <div class="smallBox">
                        <span class="money"> ￥{{ item.money }}</span>
                        <span class="desc"><s> {{ item.desc }}</s></span>
                    </div>
                </div>
                <div class="right">
                    <div class="jiaBox" @click="add(item)">
                        <div class="jia">+</div>
                    </div>
                    <div class="status"> {{ item.count }} </div>
                    <div class="jianBox">
                        <div class="jian" @click="sub(item)">-</div>
                    </div>
                </div>
            </div>
        </div>
        <div class="bottom">
            <div class="price">总价：<span class="price-total">{{ totalPrice }}</span></div>
            <div class="count">总数：<span class="count-total">{{ totalCount }}</span></div>
        </div>
    </div>
</body>

</html>
<script src="./vue-2.5.21.js"></script>
<script>
    var v = new Vue({       //实例化Vue对象
        el: '#app',     //Vue实力挂载的dom节点
        //data：funcgtion(){ return {} }
        data: {     //定义响应式数据
            tasklist: [
                { id: 1, pic: './images/1.jpg', name: '秋刀鱼/斤', money: 35.00, desc: '￥35', count: 1 },
                { id: 1, pic: './images/2.jpg', name: '鲜大带鱼/条', money: 45.00, desc: '￥45', count: 1 },
                { id: 1, pic: './images/3.jpg', name: '鲜活全母皮皮虾/斤', money: 85.00, desc: '￥85', count: 1 },
                { id: 1, pic: './images/4.jpg', name: '13-15头鲍鱼/只', money: 105.00, desc: '￥105', count: 1 }
            ]
        },
        computed: {
            totalCount() {
                var sum = 0
                this.tasklist.forEach((item) => {
                    sum = sum + item.count
                })
                return sum
            },
            totalPrice() {
                var sum = 0
                this.tasklist.forEach((item) => {
                    sum += item.money * item.count
                })
                return sum
            },
        },     //定义计算属性
        watch: {},        //定义数据监听
        methods: {
            add(item) {
                // console.log(item);
                if (item.count <= 4) item.count++
            },
            sub(item) {
                // console.log(item);
                if (item.count > 1) item.count--
            },
            clean() {
                this.tasklist = []
            }
        },     //定义方法（函数）
        filters: {},     //定义过滤器
        directives: {},      //定义自定义指令
        components: {}       //注册局比组件
    })
</script>